Skip to content

Conversation

@G4URAV001
Copy link

@G4URAV001 G4URAV001 commented Apr 25, 2025

📋 Description

Closes PSMRI/AMRIT#85
JIRA ID: issue link

This PR implements commit message linting and automation for all contributors in the API repositories using Commitlint, Husky, and Commitizen. The aim of this initiative is to enforce a consistent and readable commit history, improving collaboration and enabling future automated changelogs and CI/CD processes. This setup aligns with the practices followed across all C4GT Community repositories.

  • Every commit in API repositories will follow the defined structure (e.g., Conventional Commits).

  • Husky will block non-compliant commit messages locally.

  • Contributors will use Commitizen (cz) to follow a guided commit format.

  • GitHub Actions will fail PR checks if commit messages do not follow the required format.

  • All changes will be compatible with the existing CI/CD pipelines, ensuring smooth integration.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

•⁠ ⁠Added ⁠ commitlint.config.js ⁠ with conventional commit rules.
•⁠ ⁠Configured Husky to run Commitlint on every commit via ⁠ .husky/commit-msg ⁠.
•⁠ ⁠Set up ⁠ Commitizen ⁠ with configuration in ⁠ package.json ⁠ for interactive commit prompts.
•⁠ ⁠Added GitHub Actions workflow ⁠ .github/workflows/commit-lint.yml ⁠ to check commit messages on PRs.
•⁠ ⁠Updated ⁠ package.json ⁠ and ⁠ package-lock.json ⁠ with required dev dependencies:

  • ⁠ @commitlint/cli ⁠
    ⁠ - @commitlint/config-conventional ⁠
    ⁠ - commitizen ⁠
    ⁠ - cz-conventional-changelog ⁠

Testing & Validation
•⁠ ⁠Invalid commit messages are blocked locally with clear lint errors.
•⁠ ⁠Interactive commit flow works via ⁠ npm run commit ⁠ or ⁠ npx cz ⁠.
•⁠ ⁠GitHub Actions workflow correctly fails PRs with non-compliant commit messages.
•⁠ ⁠No disruption to existing build or CI pipelines.
Screenshot 2025-04-25 205804
Screenshot 2025-04-25 205819

Summary by CodeRabbit

  • New Features
    • Introduced automated commit message linting for pull requests and local commits to enforce standardized commit message conventions.
    • Added documentation on setting up commit hooks, commit message guidelines, and usage of Commitizen for easier commit formatting.
  • Chores
    • Added configuration files and dependencies to support commit message linting and Git hook integration.
    • Updated README with setup instructions and minor punctuation corrections.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

This change introduces a complete commit message linting and enforcement system using Commitlint, Husky, Commitizen, and GitHub Actions. A new workflow is added to automatically check commit message compliance on pull requests. Husky is configured to lint commit messages locally via a Git hook. The Commitlint configuration is defined with specific rules for commit message structure and allowed types. Commitizen is set up to assist with standardized commit creation. The README is updated with detailed instructions on setting up and using these tools, including the commit message convention, prerequisites, and usage examples.

Changes

File(s) Change Summary
.github/workflows/commit-lint.yml Added GitHub Actions workflow to lint commit messages on pull request events.
.husky/commit-msg Added Husky Git hook script to run Commitlint during the commit-msg phase.
commitlint.config.js Introduced Commitlint configuration with rules for commit message format and allowed types.
package.json Added project metadata, npm scripts for Husky and Commitizen, and devDependencies for Commitlint, Commitizen, and Husky.
README.md Updated with punctuation fixes and a new section detailing commit hook setup, usage, and commit message conventions.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Husky (Git Hook)
    participant Commitlint
    participant Commitizen
    participant GitHub Actions

    Developer->>Commitizen: Run "npm run commit"
    Commitizen->>Developer: Prompt for commit message fields
    Developer->>Husky (Git Hook): git commit
    Husky (Git Hook)->>Commitlint: Lint commit message (--edit)
    Commitlint-->>Husky (Git Hook): Pass/Fail result
    Husky (Git Hook)-->>Developer: Allow/Block commit

    Developer->>GitHub: Push changes / open PR
    GitHub->>GitHub Actions: Trigger commit-lint workflow
    GitHub Actions->>Commitlint: Lint all PR commit messages
    Commitlint-->>GitHub Actions: Pass/Fail result
    GitHub Actions-->>GitHub: Report status on PR
Loading

Possibly related issues

Poem

In the warren where code is tight,
We lint our commits, both day and night.
With Husky’s paws and Commitlint’s might,
Our messages now are a tidy sight.
Commitizen hops in to help us write,
And GitHub Actions checks if all is right—
Now every merge is a bunny’s delight!

((\
( -.-)
o_(")(")

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

@G4URAV001
Copy link
Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
.github/workflows/commit-lint.yml (1)

30-30: Remove trailing spaces and ensure newline at end-of-file.

YAMLlint reports trailing spaces on line 30 and no final newline. Please remove the extra whitespace and add a newline at EOF to satisfy linting rules.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)


[error] 30-30: trailing spaces

(trailing-spaces)

README.md (4)

32-32: Fix Markdown link formatting.

There’s an unintended space in the link syntax which breaks the URL:

- For step-by-step guide, follow this [guide] (https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup) .
+ For step-by-step guide, follow this [guide](https://piramal-swasthya.gitbook.io/amrit/developer-guide/development-environment-setup).
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

32-32: Bare URL used
null

(MD034, no-bare-urls)


71-73: Specify language for fenced code block.

To satisfy markdownlint (MD040) and improve readability, add a language identifier:

- ``` 
+ ```bash
  node --version
  npm --version

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

71-71: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

---

`79-80`: **Specify language for fenced code block.**

Add a language to the npm install code block for consistency:

```diff
- ``` 
+ ```bash
  npm ci

---

`111-113`: **Specify language for Commitizen example code block.**

Include a shell/language identifier:

```diff
- ```
+ ```bash
  npm run commit

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 7c84b7393ff6ff469f62bf8ab4aff6250b156b40 and d13dd4477f868f158aae255a9bfc607947b56f09.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `package-lock.json` is excluded by `!**/package-lock.json`

</details>

<details>
<summary>📒 Files selected for processing (5)</summary>

* `.github/workflows/commit-lint.yml` (1 hunks)
* `.husky/commit-msg` (1 hunks)
* `README.md` (3 hunks)
* `commitlint.config.js` (1 hunks)
* `package.json` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 YAMLlint (1.35.1)</summary>

<details>
<summary>.github/workflows/commit-lint.yml</summary>

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

---

[error] 30-30: trailing spaces

(trailing-spaces)

</details>

</details>
<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>README.md</summary>

[uncategorized] ~69-~69: The official spelling of this programming framework is “Node.js”.
Context: ...d npm**    - Download and install from [nodejs.org](https://nodejs.org/)    - Verify i...

(NODE_JS)

---

[uncategorized] ~81-~81: Possible missing comma found.
Context: ...```    - This will install all required dependencies including Husky and commitlint  3. **Ve...

(AI_HYDRA_LEO_MISSING_COMMA)

---

[grammar] ~95-~95: “Bug” is a singular noun. It appears that the verb form is incorrect.
Context: ... - `feat`: A new feature - `fix`: A bug fix - `docs`: Documentation changes - `styl...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)

---

[uncategorized] ~98-~98: Loose punctuation mark.
Context: ... changes (formatting, etc.) - `refactor`: Code changes that neither fix bugs nor ...

(UNLIKELY_OPENING_PUNCTUATION)

</details>

</details>
<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

<details>
<summary>README.md</summary>

71-71: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

---

78-78: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

---

110-110: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (2)</summary><blockquote>

<details>
<summary>.github/workflows/commit-lint.yml (1)</summary>

`1-29`: **Commit Compliance workflow is properly configured.**

The GitHub Actions workflow triggers on pull request events, checks out the correct ref with full history, sets up Node.js, installs dependencies, and runs `commitlint` between head and base SHAs. This aligns with the PR objective to enforce commit message linting in CI.

</details>
<details>
<summary>commitlint.config.js (1)</summary>

`1-36`: **Commitlint configuration correctly enforces Conventional Commits.**

The rules extend the conventional preset, enforce body/footer blank lines, limit line lengths, restrict subject punctuation and casing, and tightly define allowed types. This aligns with project objectives and ensures clear, consistent commit messages.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@@ -0,0 +1 @@
npx --no -- commitlint --edit $1 No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Add Husky hook initialization and shebang to the commit-msg hook.

The current script omits the required shebang and Husky shim import, so Git won’t source the Husky environment. Without this, the hook may not execute correctly.

Apply this diff:

- npx --no -- commitlint --edit $1 
+ #!/usr/bin/env sh
+ . "$(dirname "$0")/_/husky.sh"
+ npx --no -- commitlint --edit "$1"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx --no -- commitlint --edit $1
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- commitlint --edit "$1"

Comment on lines +6 to +7
"prepare": "husky",
"commit": "cz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct the prepare script to properly install Husky hooks.

Husky v7+ expects husky install to set up the .husky directory and hooks. Using husky alone may not install the hooks.

-"prepare": "husky",
+"prepare": "husky install",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C4GT Community]: Implement Commit Message Linting and Automation for TM-API

1 participant